using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using SypConst.Garbage;

namespace SypEngine.TransferHandler
{
    public class SypLocalTransferHandler : SypTransferHandler
    {
        private string remoteCurrentPath = null;

        public override int[] CheckSynchronizedPictures(string RootDir)
        {
            return null;
        }

        public SypLocalTransferHandler(SetText outMethod, string remotepath)
            : base (outMethod)
        {
            DirectoryInfo myRemoteCurrentPath = new DirectoryInfo(remotepath);
            this.remoteCurrentPath = myRemoteCurrentPath.FullName + "\\";
            SypGarbage.free(myRemoteCurrentPath);
        }

        public override void MakeDir(string DirPath)
        {
            try
            {
                Directory.CreateDirectory(remoteCurrentPath + DirPath);
            }
            catch (Exception e)
            {
                OutputMethod("LOCAL Error, makeDir : " + e.ToString(), Output.ERROR);
                throw new SypTransferException();
            }
        }

        public override void RemoveDir(string DirPath)
        {
            try
            {
                if (Directory.Exists(remoteCurrentPath + DirPath))
                    Directory.Delete(remoteCurrentPath + DirPath);
            }
            catch (Exception e)
            {
                OutputMethod("LOCAL Error, removeDir : " + e.ToString(), Output.ERROR);
                throw new SypTransferException();
            }
        }

        public override void DeleteFile(string FilePath)
        {
            try
            {
                if (File.Exists(remoteCurrentPath + FilePath))
                    File.Delete(remoteCurrentPath + FilePath);
            }
            catch (Exception e)
            {
                OutputMethod("LOCAL Error , deleteFile: " + e.ToString(), Output.ERROR);
                throw new SypTransferException();
            }
        }

        public override void SendFile(string LocalFilePath, string RemoteFilePath)
        {
            try
            {
                File.Copy(LocalFilePath, remoteCurrentPath + RemoteFilePath, true);
            }
            catch (Exception e)
            {
                OutputMethod("LOCAL Error , SendFile: " + e.ToString(), Output.ERROR);
                throw new SypTransferException();
            }
        }

        public override void Close() { }

        public override void SetCurrentDirectory(string Path)
        {
        }
    }
}
